package com.police.view;

import java.util.Calendar;

import com.police.R;
import com.police.activity.MainActivity;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TimePicker.OnTimeChangedListener;

public class TimePop extends LinearLayout {

	MainActivity main;
	public LinearLayout layout;
	LayoutInflater inflater;
	LayoutParams layoutParams;
	public DatePicker datePicker;
	public TimePicker timePicker;
	public EditText dateEt;
	public EditText timeEt;
	public String date;
	public String time;
	private TextView timeText;
	public TimePop(Context context,TextView timeTextView) {
		super(context);
		// TODO Auto-generated constructor stub
		main = (MainActivity) context;
		timeText = timeTextView;
		initView();
		}

	private void initView() {
		inflater = LayoutInflater.from(main);
		layout = (LinearLayout) inflater.inflate(R.layout.date_view, null);
		layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);

		this.addView(layout, layoutParams);

		datePicker = (DatePicker) findViewById(R.id.datePicker);
		timePicker = (TimePicker) findViewById(R.id.timePicker);
		timeEt=(EditText)findViewById(R.id.timeEt);
		dateEt=(EditText)findViewById(R.id.dateEt);
		Calendar calendar = Calendar.getInstance();
		int year = calendar.get(Calendar.YEAR);
		int monthOfYear = calendar.get(Calendar.MONTH);
		int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		datePicker.init(year, monthOfYear, dayOfMonth,
				new OnDateChangedListener() {

					public void onDateChanged(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						date = year + "年" + (monthOfYear + 1) + "月"
								+ dayOfMonth + "日";
						Log.e("date", date);
						  dateEt.setText("您选择的日期是："+year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日。");
						  if (timeText != null) {
							  timeText.setText(date);
						  }
					}

				});

		timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {

			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				time = hourOfDay + "时" + minute + "分。";
				Log.e("time", time);
				 timeEt.setText("您选择的时间是："+hourOfDay+"时"+minute+"分。");
			}

		});
		
		
	}
	

}
